package com.leozhang.portalssm.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.leozhang.portalssm.entity.*;
import com.leozhang.portalssm.mapper.EquipmentMapper;
import com.leozhang.portalssm.mapper.EquipmentbrandMapper;
import com.leozhang.portalssm.service.EquipmentBrandService;
import com.leozhang.portalssm.util.ChangeChar;
import com.leozhang.portalssm.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Transactional
@Service
public class EquipmentBrandServiceImpl implements EquipmentBrandService {

    @Autowired
    private EquipmentbrandMapper equipmentbrandMapper;


    @Override
    public Result getListForPage(int pno, int psize, String brandName, String sortField, String sortType) {
        Page<Object> p = PageHelper.startPage(pno, psize);
        EquipmentbrandExample example = new EquipmentbrandExample();
        EquipmentbrandExample.Criteria criteria = example.createCriteria();
        if(brandName.trim().length()>0){
            criteria.andBrandNameLike("%"+brandName+"%");

        }
        if(sortField.trim().length()>0){
            example.setOrderByClause(ChangeChar.camelToUnderline(sortField,2) +""+sortType);
        }
        List<Equipmentbrand> list = equipmentbrandMapper.selectByExample(example);
        return Result.end(200,list,"查询成功",p.getTotal());
    }

    @Override
    public void insertequipmentbrand(Equipmentbrand equipmentbrand) {
        equipmentbrandMapper.insert(equipmentbrand);
    }

    @Override
    public void deleteequipmentById(Long id) {
        equipmentbrandMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Equipmentbrand selectequipmentBrandById(Long id) {
        Equipmentbrand equipmentbrand = equipmentbrandMapper.selectByPrimaryKey(id);
        return equipmentbrand;
    }

    @Override
    public void updateEquipmentBrand(Equipmentbrand equipmentBrand) {
        equipmentbrandMapper.updateByPrimaryKeySelective(equipmentBrand);
    }

    @Override
    public List<Equipmentbrand> selectListAll() {
        return equipmentbrandMapper.selectByExample(null);
    }
}
